import store from '../store/index';
export default {
	// BASEURI: 'https://qsg.wuminginfo.com/api/',
	// ESURI: 'https://qsg.wuminginfo.com/api/',
	BASEURI: 'https://yzadmin.jxoem.com/api/',
	ESURI: 'https://yzadmin.jxoem.com/api/',
	// BASEURI: 'http://localhost:8081/api/',
	// ESURI: 'http://localhost:8081/api/',
	
	// BASEURI: 'https://qsg.csqsg.com/api/',
	// ESURI: 'https://qsg.csqsg.com/api/',
	
	STORE_ID : 369,
	gateway:{
		getGateways:'gatewayDevice/list',
		operate:'gatewayDevice/operate'
	},
	certificate:{
		list:'certificate/list',
		listByStore:'certificate/listCertByStore',
		certPay:'pay/certPay'
	},
	integral:{
		listByMember:'dms/recharge/listByMember',
		listHexiaoDetail:'dms/hexiao/list'
	},
	store:{
		getAllStore:'store/list',
		getStoreById:'qsg/store/getStoreById'
	},
	device:{
		getDevices:'dms/device/list',
		getDeviceById:'dms/getDeviceById',
		getDeviceMeal:'dms/device/getDeviceMeal',
		getMealById:'dms/meal/getMealById',
		saleMeal:'dms/meal/saleMeal',
		getRoomStatus: 'dms/room/getRoomStatus',
	},
	qsg:{
		getAllStore:'qsg/store/list',
		bestStore:'qsg/store/bestStore',
		generate:'dms/task/generate',
		getMealByDuration:'dms/task/getMealByDuration',
		indexBanner:'dms/banner/list',
		storeBanner:'dms/banner/listStore',
		getOrderById:'dms/order/getOrderById',
		getRechargeMeal:'dms/recharge/list',
		getIntegral:'dms/integral/getIntegral',
		updateRoom:'dms/room/update',
		openDamenByUniapp:'dms/task/openDamenByUniapp',
		openDamen:'dms/task/generateDamenTask',
		openDamenForDandian:'dms/task/generateDamenTaskForDandian',
		openBaoxiang:'dms/task/generateBaoxiang',
		join:'dms/join/saveJoinInfo'
	},
	index: {
		appletLogin_by_weixin: 'applet/login_by_weixin',
		logs: 'single/home/logs', //  记录日志
		userInfo: 'single/home/userInfo', //  用户信息
	}, 
	member: {
		updateMemberPhone: 'member/updateMemberPhone' ,//更新会员手机号
		updateMemberNick: 'member/updateMemberNick',
		upload: 'member/upload' //上传头像
	},
	order: {
		duiHuan: 'order/duiHuan',
		postpaidDuiHuan: 'order/postpaidDuiHuan',
		douyinDuiHuan: 'order/douyinDuiHuan',
		postpaidDouyinDuiHuan: 'order/postpaidDouyinDuiHuan',
		tiqian:'order/tiqian',
		createOrder: 'order/generateDriverOrder',
		endOrder: 'order/endOrder',
		endYjOrder: 'order/endYjOrder',
		createBilliardOrder: 'order/generateBilliardOrder',
		createRechargeOrder: 'order/generateRechargeOrder',
		jifenPay:'pay/jifenPay',
		jifenPayForDepositDevice:'pay/jifenPayForDepositDevice',
		getCurrentOrder:'dms/meal/currentOrder',
		getYuyueOrder:'dms/meal/yuyueOrder',
		checkProtect:'order/checkProtect',
		checkIsIntersect:'order/checkIsIntersect',
		getDmsOrderDetail: 'order/getDmsOrderDetail',
		weixinAppletPay: 'pay/weixinAppletPay', // 微信小程序支付
		weixinAppletPayForDeposit: 'pay/weixinAppletPayForDeposit', // 微信小程序支付
		weixinAppletPayForRefund: 'pay/weixinAppletPayForRefund',
		payRecharge:'pay/payRecharge',
		driverOrderList: 'single/oms/driverorder/list', // 查询驾校订单列表
		coachOrderList: 'single/oms/coachOrderList/list', // 查询教练订单列表
		closeDriverOrder: 'single/oms/driverorder/closeDriverOrder', //取消订单
		cannelOrder:'order/cannelOrder',
		convert:'order/convert'
	},
	/**
	 * 封装请求（async await 封装uni.request）
	 * method	   post/get
	 * endpoint    接口方法名
	 * data		   所需传递参数
	 * load		   是否需要loading
	 */
	async apiCall(method, endpoint, data, load) {
		if (load) {
			uni.showLoading({
				title: '请稍候',
				mask: true
			});
		}
		let fullurl = this.BASEURI + endpoint;
		let Authorization;
		let storeId = data.storeId;
		console.log(data)
		if(typeof storeId == 'undefined'){
			storeId = this.STORE_ID;
		}
		if (`${store.state.userInfo}`) {
			let mid = `${store.state.userInfo.userInfo.id}`;
			if (mid) {
				data.memberId = mid;
				Authorization = `${store.state.userInfo.tokenHead}${store.state.userInfo.token}`;
			}
		}
		var contentType = 'application/x-www-form-urlencoded';

		if (endpoint.indexOf('login') != -1) {
			//	contentType = 'application/json';
		}
		let [error, res] = await uni.request({
			url: fullurl,
			data: data,
			method: method,
			header: {
				'storeid': storeId,
				//'Content-Type': 'application/x-www-form-urlencoded',
				'content-type': contentType,
				'Authorization': Authorization || ''
			},
		});
		if (load) {
			uni.hideLoading();
		}
		// console.log(res);
		if (res.data.msg == 'User token expired!') {
			uni.showToast({
				title: '请先登录',
				icon: 'none'
			});
			uni.navigateTo({
				url: `/pages/public/login`
			})
		}
		if (res.data.msg == '请先登录' || res.data.code == 100) {
			uni.showToast({
				title: '请先登录',
				icon: 'none'
			});
			uni.navigateTo({
				url: `/pages/public/login`
			})
		}
		if (res.data.code == 200) {
			return res.data.data;
		} else {
			console.log(res.data);
			if (res.data && res.data.msg) {
				uni.showToast({
					title: res.data.msg,
					icon: 'none'
				});
				//this.$api.msg(res.data.msg);
			}

		}
	},
	/**
	 * 封装请求（async await 封装uni.request）
	 * method	   post/get
	 * endpoint    接口方法名
	 * data		   所需传递参数
	 * load		   是否需要loading
	 */
	async apiCallJson(method, endpoint, data, load) {
		if (!load) {
			uni.showLoading({
				title: '请稍候',
				mask: true
			});
		}
		let fullurl = this.BASEURI + endpoint;
		let Authorization;
		let storeId = 1;
		if (`${store.state.userInfo}`) {
			let mid = `${store.state.userInfo.userInfo.id}`;
			//storeId = `${store.state.userInfo.userInfo.storeId}`;
			if (mid) {
				data.memberId = mid;
				Authorization = `${store.state.userInfo.tokenHead}${store.state.userInfo.token}`;
			}
		}
		var contentType = 'application/json;charset=UTF-8';

		if (endpoint.indexOf('login') != -1) {
			//	contentType = 'application/json';
		}
		console.log(endpoint);
		let [error, res] = await uni.request({
			url: fullurl,
			data: data,
			method: method,
			header: {
				'storeid': storeId,
				//'Content-Type': 'application/x-www-form-urlencoded',
				'content-type': contentType,
				'Authorization': Authorization || ''
			},
		});
		if (!load) {
			uni.hideLoading();
		}
		if (res.data.message == 'User token expired!') {
			uni.showToast({
				title: '请先登录',
				icon: 'none'
			});
			uni.navigateTo({
				url: `/pages/public/login`
			})
		}
		if (res.data.message == '请先登录' || res.data.code == 100) {
			uni.showToast({
				title: '请先登录',
				icon: 'none'
			});
			uni.navigateTo({
				url: `/pages/public/login`
			})
		}
		return res;
	}
}
